package com.gaoyi.crm.fragment;

import androidx.activity.result.ActivityResult;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.gaoyi.crm.R;
import com.gaoyi.crm.adapter.PromotionAdapter;
import com.gaoyi.crm.databinding.FragmentHomePageBinding;
import com.gaoyi.crm.db.dto.PmnDto;
import com.gaoyi.crm.db.query.BaseQuery;
import com.gaoyi.crm.fragment.base.BaseListFragment;
import com.gaoyi.crm.util.Utils;
import com.gaoyi.crm.vm.HomePageViewModel;

import java.util.Date;
import java.util.Map;

public class HomePageFragment extends BaseListFragment<FragmentHomePageBinding, HomePageViewModel, PmnDto, BaseQuery> {

    private PromotionAdapter mAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home_page;
    }

    @Override
    protected void initView() {
        mSmartRefreshLayout = mBinding.smartRefreshLayout;
        mBinding.smartRefreshLayout.setEnableLoadMore(false);
        mAdapter = new PromotionAdapter(mContext);
        mBinding.rvPromotion.setLayoutManager(new LinearLayoutManager(mContext));
        mBinding.rvPromotion.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        mViewModel.clearListValue();
        mViewModel.getPmns(10);
    }

    @Override
    protected void initLiveData() {
        mViewModel.getList().observe(getViewLifecycleOwner(), pmnDtos -> mAdapter.submitList(pmnDtos));
        mViewModel.getResultCode().observe(getViewLifecycleOwner(), integer -> Utils.refreshSmartRefreshLayout(mBinding.smartRefreshLayout));
    }

    @Override
    protected void loadData() {
        mViewModel.getPmns(10);
    }

    @Override
    protected void search(Date startDate, Date endDate) {

    }

    @Override
    protected void search(String keyWord) {

    }

    @Override
    protected void sort(int id, Integer sort) {

    }

    @Override
    protected BaseQuery createQuery() {
        return new BaseQuery();
    }

    @Override
    protected void onRequestPermissionsResult(Map<String, Boolean> result) {

    }

    @Override
    protected void onActivityResult(int requestCode, ActivityResult result) {

    }
}